﻿<%@ WebHandler Language="C#" Class="LoginAuth" %>

using System;
using System.Web;
using System.Web.Services;
using Microsoft.AspNet.SignalR;

[WebService(Namespace = "http://www.ccp.com.tw/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class LoginAuth : IHttpHandler {
    
    //繼承介面IHttpHander須實做ProcessRequest函式
    public void ProcessRequest (HttpContext context) {
        try
        {
            HttpRequest req = context.Request;

            //取得俊潢的WebService POST過來的參數
            string sip_num = req.Form["SIP_Num"];
            string pps_code = req.Form["PPS_CODE"];
            string custom_name = req.Form["CustomName"];
            string user_dir = req.Form["UserDir"];
            string cmd = req.Form["Command"];
            string cid = cmd.Substring(27);

            //傳訊息到前端
            SendMessageToClient(cid, sip_num, pps_code, custom_name, user_dir);
        }
        catch (Exception ex)
        {
        }
    }

    //傳送訊息至Web Client端
    public void SendMessageToClient(string connection_id, string sip_number, string pps_code, string custom_name, string user_dir)
    {
        try
        {
            //取得LoginHub 的HttpContext
            var context = GlobalHost.ConnectionManager.GetHubContext<LoginHub>();

            //從LoginHub Server端呼叫傳訊息函式
            context.Clients.All.GetMessage(connection_id + ',' + sip_number + ',' + pps_code + ',' + custom_name + ',' + user_dir);
        }
        catch(Exception ex)
        {
        }
    }

    //繼承介面IHttpHander須實做IsReusable函式
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}